import client from '../utils/client.js';
import {LIMIT} from '../store/constant'
// 偏移量:从第几页开始查
const OFFSET = (page)=>{
    return (page-1) *LIMIT
}

const articleAPI = {
    createArticle: article => client.post('/articles', {article}),
    getArticlesBySlug: slug => client.get(`/articles/${slug}`),
    updateArticle: (article,slug) => client.put(`/articles/${slug}`,{article}),
    deteleArticle:slug => client.delete(`/articles/${slug}`),
    getAllArticles: (page)=> client.get(`/articles?limit=${LIMIT}&offset=${OFFSET(page)}`),
    getTagArticles: (tag,page)=> client.get(`/articles?tag=${tag}&limit=${LIMIT}&offset=${OFFSET(page)}`),
}

export default articleAPI;
